<?php
/**
 * Created by PhpStorm.
 * User: changshuiwang
 * Date: 2016/7/8
 * Time: 13:43
 */
namespace common\models;

use Yii;
use yii\base\Model;
use yii\web\UploadedFile;

/**
 * Login form
 */
class UpdateForm extends Model
{
    public $id;
    public $username;
    //public $score;
    public $photo;

    private $_student;


    public function rules()
    {
        return [
            [['id', 'username'], 'required'],
            [['username'],'match','pattern'=>'/^[a-z0-9\-_]+$/'],
            [['username'], 'string', 'length'=>[4,24], 'message'=>'用户名请输入长度为2-7个字'],
            //[['score'], 'number', 'message'=>'分数请输入数字'],
            [['photo'],'safe'],
        ];
    }

    /**
     *
     */
    public function reload($array){
        if(is_array($array)){
            $this->username=$array['username'];
            $this->score=$array['score'];
            $this->id=$array['id'];
        }else{
            $this->username=$array->username;
            $this->score=$array->score;
            $this->id=$array->id;
        }
    }
    
    /**
     * 
     */
    public function update(){
        return Student::modifyStudent($this);
    }

}